<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html lang="en">
<head>
	<title>Latin Nouns</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="../classics.css" rel="stylesheet" type="text/css">
</head>

<?php

$endings = array('Singular' => array('Nom.' => 'a', 'Gen.' => 'ae', 'Dat.' => 'ae', 'Acc.' => 'am', 'Abl.' => 'ā'),
	             'Plural' => array('Nom.' => 'ae', 'Gen.' => 'ārum', 'Dat.' => 'īs', 'Acc.' => 'ās', 'Abl.' => 'īs'));

$stems = array('caus', 'fortūn', 'fīli', 'de', 'mens', 'aquil', 'lūn', 'rēgīn', 'stell');

$stem = $stems[mt_rand(0, count($stems) - 1)];

$vtab = "<caption>".$stem."a</caption>\n";
$vtab = $vtab . "<tr><td></td><th>Singular</th><th>Plural</th></tr>\n";

foreach(array('Nom.', 'Gen.', 'Dat.', 'Acc.', 'Abl.') as $case) {
	$vtab = $vtab . "<tr><th>$case</th>";
	foreach(array('Singular', 'Plural') as $number) {
		$vtab = $vtab . "<td>";
		if (($stem == 'fīli' || $stem == 'de') && ($number == 'Plural') && ($case == 'Dat.' || $case == 'Abl.')) {
			$nouns[] = $stem.'ābus';
			$vtab = $vtab . "<input name=\"text".(count($nouns) - 1)."\" type=\"text\">";
		} elseif (isset($endings[$number][$case])) {
			$nouns[] = $stem.$endings[$number][$case];
			$vtab = $vtab . "<input name=\"text".(count($nouns) - 1)."\" type=\"text\">";
		}
		$vtab = $vtab . "</td>";
	}
	$vtab = $vtab . "</tr>\n";
}
?>

<script type="text/javascript">
function check() 
{

<?php
	for($i = 0, $nall = count($nouns); $i < $nall; $i++) {
		print "if (document.n01.text".$i.".value=='".$nouns[$i]."')\n{\n";
		print "\tdocument.n01.text".$i.".disabled=true;\n}\n";
	}
?>

}

function newWord() 
{
<?php
	for($i = 0, $nall = count($nouns); $i < $nall; $i++) {
		print "document.n01.text".$i.".disabled=false;\n";
 		print "document.n01.text".$i.".value='';\n";
	}
?>
	location.reload();
}
</script>

<body>
<div id="container">
<div id="center">
<form name="n01" action="">
<table align="center">
<?php
	print $vtab;
?>
<tr><td></td>
	<td align="center"><input name="Check" onclick="check()" value="Check" type="button"></td>
	<td align="center"><input name="New Word" onclick="newWord()" value="New Word" type="button"></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
